package cn.kgc.springcloud.controller;

import cn.kgc.springcloud.entity.City;
import cn.kgc.springcloud.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: 课工场
 * @Version: v1.0  2023/4/28
 * @Description:
 */
@RestController
@RequestMapping("city")
public class CityController {

    @Autowired
    private CityService cityService;

    @GetMapping
    public List<City> getList() {
        return cityService.list();
    }

    @PostMapping
    public City add(@RequestBody City city) {
        cityService.save(city);
        return city;
    }

    @GetMapping("{id}")
    public City getById(@PathVariable("id") Integer id) {

        return   cityService.getById(id);

    }


}
